﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Entity;
using DAL;

namespace Project_V1
{
    public partial class FrmLcok : Form
    {
        public FrmLcok()
        {
            InitializeComponent();
        }

        #region 窗体移动
        private Point mouseOff;
        private bool leftFlag;
        private void Frm_MouseDown(object sender,MouseEventArgs e)
        {
            if (e.Button==MouseButtons.Left)
            {
                mouseOff = new Point(-e.X, -e.Y);
                leftFlag = true;
            }
        }
        private void Frm_MouseMove(object sender,MouseEventArgs e)
        {
            if (leftFlag)
            {
                Point mouseSet = Control.MousePosition;
                mouseSet.Offset(mouseOff.X, mouseOff.Y);
                Location = mouseSet;
            }
        }
        private void Frm_MouseUp(object sender,MouseEventArgs e)
        {
            if (leftFlag)
            {
                leftFlag = false;
            }
        }
        #endregion

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        private void OpenWindow(Form Frm)
        {
            Frm.TopLevel = false;
            Frm.FormBorderStyle = FormBorderStyle.None;
            Frm.Dock = DockStyle.Fill;
            //Frm.Parent = FrmMain.MainPanel;
            Frm.Show();
            Frm.TopMost = false;

        }
        //登录按钮,输入验证
        private void btnLoginSys_Click(object sender, EventArgs e)
        {
            //if (this.txtLoginAccount.Text.Trim().Length==0)
            //{
            //    MessageBox.Show("请输入用户名!","提示信息");
            //    this.txtLoginAccount.Focus();//光标闪烁
            //    return;//下面的代码不执行
            //}
            if (this.txtLoginPwd.Text.Trim().Length == 0)
            {
                MessageBox.Show("请输入密码!", "提示信息");
                this.txtLoginPwd.Focus();//光标闪烁
                return;//下面的代码不执行
            }
            //封装对象
            SysAdmins objAdmins = new SysAdmins()
            {
                //LoginId = Convert.ToInt32(this.txtLoginAccount.Text.Trim()),
                LoginPwd = this.txtLoginPwd.Text.Trim()
            };

            if ( objAdmins.LoginPwd != "123456")//objAdmins.LoginId != 10000 &&
            {
                MessageBox.Show("用户名或密码错误！", "登录提示");
            }
            else
            {
                this.DialogResult = DialogResult.OK;

                //if (CloseWindow("FrmMaintenance") == false)
                //{
                 //   OpenWindow(new FrmMaintenance());
                    //this.lbl_Title.Text = " " + ((Button)sender).Tag.ToString();
                    //BackColorSet(((Button)sender).Tag.ToString());
                //}

                //CommonMethods.objAdmins = objAdmins;
            }
        }

         
        private void txt_UserId_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                this.btnLoginSys_Click(null, null);
            }
        }
        private void txt_Pwd_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                this.btnLoginSys_Click(null, null);
            }
        }
        private void tb_Click(object sender, EventArgs e)
        {
            TextBox tb_temp = (TextBox)sender;
            FrmKeyPad.input = tb_temp.Text;
            // 获取 TextBox 的屏幕位置
            Point textboxLocation = tb_temp.PointToScreen(Point.Empty);
            // 创建一个新的窗体
            FrmKeyPad frmSoftKey = new FrmKeyPad(tb_temp.Text);
            // 计算窗体的位置
            //textboxLocation.X = 1;
            //textboxLocation.Y = 1;
            int popupX = textboxLocation.X;
            int popupY = textboxLocation.Y;
            // 设置窗体的位置
            frmSoftKey.Location = new Point(popupX, popupY);
            // 显示窗体
            frmSoftKey.ShowDialog();
            //MessageBox.Show("显示键盘之后");
            //MessageBox.Show(FrmSoftKey.input);
            if (FrmKeyPad.confirm)
            {
                tb_temp.Text = FrmKeyPad.input;
                tb_temp.SelectionStart = tb_temp.Text.Length;
                tb_temp.SelectionLength = 0;
                tb_temp.Focus();
            }
        }

        private void FrmLcok_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
